package com.pozu.new_retail.service.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pozu.new_retail.dao.mapper.UserMapper;
import com.pozu.new_retail.dao.model.User;
import com.pozu.new_retail.dao.vo.BriefUserVo;
import com.pozu.new_retail.dao.vo.UserVo;
import com.pozu.new_retail.service.UserService;

@Service("userService")
public class UserServiceImpl implements UserService {

	@Autowired
	private UserMapper userMapper;

	@Override
	public User queryByUserId(long userId) {
		return userMapper.queryByUserId(userId);
	}

	public User queryByOpenId(String openId) {
		return userMapper.queryByOpenId(openId);
	}

	@Override
	public int saveUser(User user) {

		long time = System.currentTimeMillis();

		user.setCreatedTime(time);

		user.setUpdatedTime(time);

		return userMapper.insertUser(user);
	}

	@Override
	public int updateUser(User user) {
		user.setUpdatedTime(System.currentTimeMillis());
		return userMapper.updateUser(user);
	}

	@Override
	public UserVo queryByPhone(String phone) {
		
		UserVo vo = userMapper.queryByPhone(phone);
				
		return vo;
	}

	@Override
	public List<BriefUserVo> queryUsersByMap(HashMap<String, Object> map) {
		return userMapper.queryUsersByMap(map);
	}

}
